Loguru logging#113
Open
Hendrik-code wants to merge 4 commits into
Open
Conversation
…vels) Add loguru dep and a new TPTBox/logger/_loguru_backend.py: each Log_Type maps to a custom TPTBOX_* Loguru level whose color markup reproduces the exact ANSI of type2bcolors (light-cyan->96, bg blue->44, ...). print_to_terminal now emits via a colorized Loguru function-sink (writing to the live sys.stdout, honoring end so end='\r' progress lines are intact). WARNING_THROW still routes to warnings.warn. Public API/classes/verbose semantics unchanged. Verified: 28/28 golden cases render identically (only invisible reset-code differences) and all 15 non-default Log_Types emit the exact expected color code. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…on/retention) Logger now writes via a Loguru file sink instead of raw file.write. Default keeps its own handle behind a Loguru function-sink (flush() works, 'end' honored, ANSI-free, atexit-safe duration line). New rotation=/retention=/enqueue kwargs switch to a Loguru-owned path sink for rotation & retention. Per-instance record filtering keeps multiple Loggers' files isolated. Verified: exact filename scheme + header/duration lines, no ANSI in files, rotation produces multiple files, two-logger isolation, and the duration line is still written at interpreter exit for unclosed loggers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…r sinks print_error now also emits a structured Loguru record (opt(exception=True), bound to an 'exception' channel the default sinks ignore) so user sinks capture the traceback; the human-readable text output is unchanged. Add install_excepthook() to route uncaught exceptions through Loguru (opt-in). Re-export configure, install_excepthook, and the configured loguru_logger from TPTBox.logger so callers can attach their own sinks (JSON via serialize=True, level filtering on TPTBOX_*). Configure now runs eagerly at import so the take-over logger.remove() only drops Loguru's own default handler and never wipes user sinks added afterwards. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add unit_tests/test_logger.py (10 tests) asserting the backwards-compat contract: per-Log_Type terminal coloring matches type2bcolors, carriage-return end preserved, WARNING_THROW->warnings.warn, verbose gating, ANSI-free + isolated file output, and structured exception capture into user sinks. Document the Loguru backend, TPTBOX_* levels, take-over opt-out, rotation/retention, user sinks, and exception capture in the logger README. Full unit suite: 405 passed / 4 skipped; thread safety verified (3200 concurrent lines, no interleaving). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Open
Collaborator
|
Dont care |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the
TPTBox.loggeremission layer to Loguru while keeping the public API and terminal color coding unchanged. This is a Loguru-backed facade: every public class, method signature,Log_Type,verbosesemantic,sub-logger,
String_Logger,Reflection_Logger, the globallog, theloggingalias,on_*/print_error/log_statistic,.prefix/.default_verbose, andcreate_from_bidsare preserved.Loguru replaces only the two emission primitives (the terminal write and the
Loggerfile write), all isolated behind a newTPTBox/logger/_loguru_backend.py(the only module that imports loguru).Backwards compatibility & color coding
Log_Typemaps to a customTPTBOX_*Loguru level whose color markup reproduces the exact original ANSI (<light-cyan>→\033[96m,<bg blue>→\033[44m,<italic>,<underline>, …).unit_tests/test_logger.py, 10 tests) locks the contract againsttype2bcolors. Verified: 28/28 golden cases render identically (only invisible reset-code differences) and all 15 non-defaultLog_Types emit the exact color code.end="\r"progress lines are preserved (the terminal sink honorsendinstead of Loguru's forced newline),WARNING_THROWstill routes towarnings.warn, andverbose=Falsestill suppresses.Loggers stay isolated.New capabilities (all opt-in, no behavior change by default)
enqueue=Truefor multiprocessing.Logger(..., rotation="20 MB", retention="10 days", enqueue=True).from TPTBox.logger import loguru_logger; loguru_logger.add("run.jsonl", serialize=True, level="TPTBOX_WARNING").print_erroremits a structured record to user sinks; opt-ininstall_excepthook()routes uncaught exceptions through Loguru.Notes for reviewers
TPTBOX_LOGGER_TAKEOVER=0set before importing TPTBox.Configuring eagerly at import (rather than lazily) is deliberate — it ensures user sinks added afterwards are never wiped by the take-over
logger.remove().loguru = "^0.7.2"topyproject.toml.